const Koa = require("koa");
const koaStaticCache = require("koa-static-cache");
const path = require("path");
const app = new Koa();
app.use(
  koaStaticCache(__dirname + `/static`, {
    prefix: "/public", //如果当前请求的url是以/public开始，则作为静态资源请求
    // localhost:3000/public/1.txt 实际上是访问的d:\wx\vue-learning-demo\koa\static\1.txt
  })
);

app.use(async (ctx, next) => {
  console.log("ctx.url", ctx.url);
  await next();
  //   if (ctx.status === 404) {
  //     ctx.redirect("/public/index.html");
  //   }
});

app.listen(3000, "localhost");
